package org.alex.samples.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Utils {

	public static String GetMD5Code(String strObj){
		String resultString=null;
		try{
			resultString=new String();
			MessageDigest md=MessageDigest.getInstance("MD5");
			resultString=byteToString(md.digest(strObj.getBytes()));
		}catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return resultString;
	}

	private static String byteToString(byte[] digest) {
		StringBuffer sBuffer=new StringBuffer();
		for(int i=0;i<digest.length;i++){
			sBuffer.append(byteToArrayString(digest[i]));
		}
		return sBuffer.toString();
	}

	private static Object byteToArrayString(byte b) {
		// TODO Auto-generated method stub
		return b;
	}
	
}
